package code

import (
	"fmt"
	"sync"
	"time"
)

var w sync.WaitGroup

// 泛型是1.18 版本新增的功能
func Concurrence2() {
	w.Add(2) // 添加两个任务
	start := time.Now().UnixMilli()
	go task21()
	go task22()
	w.Wait()
	end := time.Now().UnixMilli() - start
	fmt.Println("总共耗时：", end)
}

func task21() {
	time.Sleep(time.Second * 3)
	fmt.Println("task1 执行")
	w.Done()
}

func task22() {
	time.Sleep(time.Second * 1)
	fmt.Println("task2 执行")
	w.Done()
}
